<template>
    <el-cascader size="mini" separator="-" :value="value" :options="treeData" :props="props"
        @change="changeValue"></el-cascader>
</template>

<script>
import { getDepartment } from "@/api/department"
import { transListToTreeData } from "@/utils"
export default {
    components: {},
    props: {
        value: {
            type: Number,
            default: null,
        }
    },
    data() {
        return {
            treeData: [],//赋值给级联组件的optons属性
            props: {
                label: "name",
                value: "id",
            }
        }
    },
    computed: {},
    methods: {
        async getDepartment() {
            this.treeData = transListToTreeData(await getDepartment(), 0)
        },
        changeValue(value) {
            if (value.length > 0) {
                this.$emit("input", value[value.length - 1])//将最后一位的id赋值给父组件的value属性
            } else {
                this.$emit("input", null)
            }
        }
    },
    created() {
        this.getDepartment()
    },
    mounted() {

    },
}
</script>
<style scoped></style>